var iconPath = '../img/icon-caravan.png'
var app = getApp()
Page({
  data: {
    markers: [],
    controls: []
  },
  regionchange(e) {
    if (e.type == 'end') {
      this.mapCtx.getCenterLocation({
        success: function(res){
          console.log(res.longitude)
          console.log(res.latitude)
        }
      })
    }
  },
  markertap(e) {
    console.log(e.markerId)
  },
  controltap(e) {
    this.mapCtx.moveToLocation()
    console.log(e.controlId)
  },
  onReady: function (e) {
    var that = this
    that.mapCtx = wx.createMapContext('map')
    wx.getLocation({
      type: 'gcj02',
      success: function(res) {
        that.setData({
          lat: res.latitude,
          lng: res.longitude
        })
      }
    })
    //that.mapCtx.moveToLocation()
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          controls: [
            {
              id: 1,
              iconPath: '../img/icon-caravan.png',
              position: {
                left: 0,
                top: res.windowHeight - 60,
                width: 50,
                height: 60
              },
              clickable: true
            }
          ]
        })
      }
    })
    app.getJson('wxapp/camps', {}, function (res) {
      that.setData({
        markers: res.data.data.map(function(d){
          return {
            title: d.name,
            iconPath: iconPath,
            id: d.id,
            latitude: d.lat,
            longitude: d.lng,
            width: 20,
            height: 20
          }
        }),
        points: res.data.data.map(function(d){
          return {
            title: d.name,
            iconPath: iconPath,
            id: d.id,
            latitude: d.lat,
            longitude: d.lng,
            width: 20,
            height: 20
          }
        })
      })
    })
  },
  onShow: function (options) {
  },
})